--***************************************************************
--
-- Parameters:
-- ObjectName               = fg{PAGE_NAME}
-- ObjectTypeName           = Filter field group
-- ScriptTree               = 0
-- ScriptOnlyActiveLanguage = 1
-- SetObjectGroups          = 1
-- LastModDate              = <NULL>
--
--***************************************************************

--*****************************************************************************************
--*** Main Object data fg{PAGE_NAME}
--*****************************************************************************************

DECLARE @intObjID INT
DECLARE @blnIsNewObject BIT 
DECLARE @intRecTypeID INT
DECLARE @intRecFieldTypeID INT
DECLARE @intObjGrpID INT
DECLARE @txtHelpHtml NVARCHAR(4000)

-- New Object ID
EXEC @intObjID = sp_zObject_ID 'Object', 'fg{PAGE_NAME}'
EXEC @intRecTypeID = sp_zObject_ID 'RecordType', 't{RECORD_TYPE}', @vblnReturnNewID = 0

 
-- Force security settings, delete current object group memberships
DELETE FROM tzObjectGroupMember WHERE ObjID = @intObjID 
DELETE FROM tzObjectField WHERE ObjID = @intObjID 

-- Init ObjectGroupID
EXEC @intObjGrpID = sp_zObject_ID 'ObjectGroup', 'Admin Data - Employee core info', @vblnReturnNewID = 0
EXEC @intRecFieldTypeID = sp_zObject_ID 'RecordType', 't{RECORD_TYPE}', @vblnReturnNewID = 0

-- Keep existing Html help text
SELECT @txtHelpHtml = HelpHTML FROM tzObjectText WHERE ObjID = @intObjID AND SysLID = 1033
-- Execute Load SP
EXEC pzObject_Load @vintObjID = @intObjID, @vstrName = N'fg{PAGE_NAME}', @vintObjTypeID = -13, @vintRecTypeID = @intRecTypeID, @vtxtComment = N'Field group for {PAGE_NAME}', @vstrFieldName = N'{PAGE_KEY}', @vintFieldRecTypeID = @intRecFieldTypeID, @vintObjGrpID = @intObjGrpID, @vstrObjGrpFieldName = N'{PAGE_KEY}', @vintSysLID = 1033, @vtxtHelpHtml = NULL
-- Reload existing Html help text
EXEC pzObjectText_Load @vintObjID = @intObjID, @vintSysLID = 1033, @vtxtHelpHtml = @txtHelpHtml

GO

--*****************************************************************************************
--*** Field Group fg{PAGE_NAME}
--*****************************************************************************************

DECLARE @intObjID INT
EXEC @intObjID = sp_zObject_ID 'Object', 'fg{PAGE_NAME}', @vblnReturnNewID = 0

EXEC pzObjectFilterFieldGroup_Load @vintObjID = @intObjID, @vintSysLID = 1033, @vstrTitle = N'{PAGE_NAME}', @vstrSourceView = N'vds{PAGE_NAME}', @vstrBoundFieldName = N'{PAGE_KEY}', @vstrSysLFieldName = N'SysLID', @vstrPKFieldName = N'{PAGE_KEY}', @vblnRelation1toN = 1, @vblnRelation1toNEmp = 1, @vblnRelation1toNPos = 1, @vintSortOrder = 10, @vblnHide = 0
GO

--*****************************************************************************************
--*** Object Parameter fg{PAGE_NAME}
--*****************************************************************************************
DECLARE @intObjID INT
DECLARE @intObjPrmID INT
DECLARE @intParentObjPrmID INT

EXEC @intObjID = sp_zObject_ID 'Object', 'fg{PAGE_NAME}', @vblnReturnNewID = 0
{SQL_FIELDGROUP_PARAMETER}